package org.neuedu.vblogserver.controller;

import com.github.pagehelper.PageInfo;
import org.neuedu.vblogserver.bean.Category;
import org.neuedu.vblogserver.bean.RespBean;
import org.neuedu.vblogserver.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;
    @GetMapping("/getCategory")
    public PageInfo getCategory(String serchKeyWord,@RequestParam(value = "pageNum",defaultValue = "1") int pageNum,@RequestParam(value = "pageSize",defaultValue = "8") int pageSize) {
        return categoryService.getCategory(serchKeyWord,pageNum,pageSize);
    }
    @PostMapping("/addCategory")
    public RespBean addCategory(@RequestBody Category category){
        System.out.println(category);

        return categoryService.addCategory(category);
    }
    @DeleteMapping("/deleteCategory/{id}")
    public RespBean deleteCategory(@PathVariable("id") int id ){
        return  categoryService.deleteCategory(id);
    }
    @DeleteMapping("/mulDeleteCategory")
    public RespBean mulDeleteCategory (int[] ids){
        return categoryService.mulDeleteCategory(ids);
    }

    @PutMapping("/updateName")
    public RespBean updateName(@RequestBody Category category){
        return categoryService.updateName(category);
    }
}
